const HtmlWebpackPlugin = require('html-webpack-plugin'); //html处理 wenpack插件
const path = require('path')
const resolve = dir => path.join(__dirname, dir); //处理文件路径
const VueLoaderPlugin = require('vue-loader/lib/plugin') //处理.vue文件所需要的插件
const merge = require('webpack-merge')

let config = null;
if (process.env.NODE_ENV == 'production') {
    config = require('./config/pro.env')
} else {
    config = require('./config/dev.env')
}
module.exports = {
    entry: './index.js',
    devtool: 'cheap-module-eval-source-map',
    devServer:{
        host: '127.0.0.1',
        port: 8888,
        noInfo: true,//配置当前项为true 控制台 将不会输出大量的信息
        hot: true, //热加载功能
        clientLogLevel: "none", //控制浏览器log日志输出
    },
    output: { //输出文件
        path: resolve('dist'),
        filename: 'build.js'
    },
    module: {
        rules: [{
                test: /\.css$/,
                use: ["vue-style-loader", "css-loader"]
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.vue$/,
                use: 'vue-loader'
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url-loader'
            },
            {
                test: /\.less/, //less 编译风格
                use: ["vue-style-loader", 'css-loader', 'less-loader']
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({ ////添加html文件插件
            template: 'index.html',
        }),
        new VueLoaderPlugin(), //添加.vue文件编译插件 实例化 
        ...config.plugins
    ],
    resolve: { //添加文件省略地址路劲
        alias: {
            'vue$': 'vue/dist/vue.js',//修改import vue地址指向 在当前项目中如果不修改 vue.runtime.esm.js:574 [Vue warn]: You are using the runtime-only build of Vue where the tem
            '@': resolve('src')
        }
    }
}
